﻿<%@ Page Title="Product" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="AddEditProduct.aspx.cs" Inherits="Admin_AddEditProduct" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <table class="style1">
                <tr>
                    <td>
                        <asp:Label ID="Label1" runat="server" Text="<u>N</u>ame" AssociatedControlID="NameText"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="NameText" runat="server" AccessKey="N" Width="450px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Display="Dynamic" runat="server" ControlToValidate="NameText" CssClass="ErrorMessage" ErrorMessage="Name is required"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label2" runat="server" Text="<u>D</u>escription" AssociatedControlID="DescriptionText"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="DescriptionText" runat="server" AccessKey="D" TextMode="MultiLine" Width="450px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" Display="Dynamic" runat="server" ControlToValidate="DescriptionText" CssClass="ErrorMessage" ErrorMessage="Description is required"></asp:RequiredFieldValidator>

                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label4" runat="server" Text="<u>P</u>roduct-type" AssociatedControlID="ProductTypeList"></asp:Label>
                    </td>
                    <td>
                        <asp:DropDownList ID="ProductTypeList" runat="server" AccessKey="P" DataSourceID="EntityDataSource1" DataTextField="Name" DataValueField="Id">
                        </asp:DropDownList>
                        <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=ProjectASPEntities" DefaultContainerName="ProjectASPEntities" EnableFlattening="False" EntitySetName="ProductType">
                        </asp:EntityDataSource>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label3" runat="server" Text="<u>B</u>rand" AssociatedControlID="BrandList"></asp:Label>
                    </td>
                    <td>
                        <asp:DropDownList ID="BrandList" runat="server" AccessKey="B" DataSourceID="EntityDataSource2" DataTextField="Name" DataValueField="Id">
                        </asp:DropDownList>
                        <asp:EntityDataSource ID="EntityDataSource2" runat="server" ConnectionString="name=ProjectASPEntities" DefaultContainerName="ProjectASPEntities" EnableFlattening="False" EntitySetName="Brands">
                        </asp:EntityDataSource>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="Button1" runat="server" Text="Back" PostBackUrl="~/Admin/Products.aspx" />
                    </td>
                    <td>
                        <asp:Button ID="SaveButton" runat="server" AccessKey="S" Text="Save" OnClick="SaveButton_Click" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <br />
                        <br />
                        <asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" DataSourceID="EntityDataSource3" InsertItemPosition="LastItem" OnItemInserting="ListView1_ItemInserting">
                            <InsertItemTemplate>
                                <br />
                                <li style="">
                                    <asp:FileUpload ID="FileUpload1" runat="server" /><br />
                                    <asp:CustomValidator ID="cusValImage" ErrorMessage="Select a valid .jpg or .jpeg file." runat="server" />
                                    <br />
                                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
                                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" CausesValidation="False" />
                                </li>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <li style="">
                                    <asp:Image ID="ImageUrl" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' />
                                    <br />
                                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" CausesValidation="False" />
                                </li>
                            </ItemTemplate>
                            <LayoutTemplate>
                                <ul class="ItemContainer">
                                    <li runat="server" id="itemPlaceholder" />
                                </ul>
                            </LayoutTemplate>
                        </asp:ListView>
                        <br />
                        <asp:EntityDataSource ID="EntityDataSource3" runat="server" ConnectionString="name=ProjectASPEntities" DefaultContainerName="ProjectASPEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EntitySetName="Pictures" Where="it.Product = @ProductId" OnInserting="EntityDataSource1_Inserting">
                            <WhereParameters>
                                <asp:QueryStringParameter Name="ProductId" QueryStringField="Id" Type="Int32" />
                            </WhereParameters>
                        </asp:EntityDataSource>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <br />
                        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1">
                            <Columns>
                                <asp:BoundField DataField="Rating" HeaderText="Rating" SortExpression="Rating" />
                                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                                <asp:BoundField DataField="User_Id" HeaderText="User_Id" SortExpression="User_Id" />
                                <asp:CommandField ShowDeleteButton="True" />
                            </Columns>
                        </asp:GridView>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ProjectASPConnectionString %>" DeleteCommand="DELETE FROM [Reviews] WHERE [Id] = @Id" InsertCommand="INSERT INTO [Reviews] ([Product], [Rating], [Description], [User_Id]) VALUES (@Product, @Rating, @Description, @User_Id)" SelectCommand="SELECT * FROM [Reviews] WHERE ([Product] = @Product)" UpdateCommand="UPDATE [Reviews] SET [Product] = @Product, [Rating] = @Rating, [Description] = @Description, [User_Id] = @User_Id WHERE [Id] = @Id">
                            <DeleteParameters>
                                <asp:Parameter Name="Id" Type="Int32" />
                            </DeleteParameters>
                            <InsertParameters>
                                <asp:Parameter Name="Product" Type="Int32" />
                                <asp:Parameter Name="Rating" Type="Int32" />
                                <asp:Parameter Name="Description" Type="String" />
                                <asp:Parameter Name="User_Id" Type="String" />
                            </InsertParameters>
                            <SelectParameters>
                                <asp:QueryStringParameter Name="Product" QueryStringField="Id" Type="Int32" />
                            </SelectParameters>
                            <UpdateParameters>
                                <asp:Parameter Name="Product" Type="Int32" />
                                <asp:Parameter Name="Rating" Type="Int32" />
                                <asp:Parameter Name="Description" Type="String" />
                                <asp:Parameter Name="User_Id" Type="String" />
                                <asp:Parameter Name="Id" Type="Int32" />
                            </UpdateParameters>
                        </asp:SqlDataSource>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

